import axios from "axios";
const instanceEC = axios.create({
  baseURL: "http://127.0.0.1:8888/api/private/v1/",
  timeout: 5000,
});
function request(req) {
  if (req.url != "login") {
    instanceEC.interceptors.request.use((config) => {
      config.headers.Authorization = window.sessionStorage.getItem("token");
      return config;
    });
  }
  instanceEC.interceptors.response.use((res) => {
    if(res.config){
      return res.data;
    }else{
      return res;
    }
  });
  return new Promise((resolve, reject) => {
    instanceEC(req)
      .then((res) => {
        resolve(res);
      })
      .catch((err) => {
        reject(err);
      });
  });
}
export default request;
